//引入Vue
import Vue from 'vue';
import VueRouter from 'vue-router';
//使用插件
Vue.use(VueRouter);
//备份VueRouter.prototype原有的push||replace方法
let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function (location,resolve,reject){
    //第一种情况：外部在使用push的时候传递成功与失败的回调
    if(resolve && reject){
        originPush.call(this,location,resolve,reject);
    }else{
        //第二种情况：外部在使用push方法时候，没有传递成功与失败的回调函数
        originPush.call(this,location,()=>{ },()=>{ });    
    }
}
VueRouter.prototype.replace = function(location,resolve,reject){
(resolve && reject)? originReplace.call(this,location,resolve,reject ):originReplace.call(this,location,()=>{ },()=>{ })
}

import routes from './routes.js'

//对外默认暴露一个Vue实例
//在路由配置的时候，对外暴露一个Router 类的实例
export default new VueRouter({
    //配置路由
    routes,
    scrollBehavior(to,form,savePosition){
        return {y:0}
    }
})